#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;


int func()
{
	int n; cin >> n;
	vector<int> v(n);
	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	int _max = 0, x = 0;

	int l = 0, r = 1;
	for (; r < n; r++)
	{
		if (v[r] - v[r - 1] >= 9)
		{
			_max = max(_max, r - l);
			l = r;
		}
	}

	_max = max(_max, r - l);


	cout << _max << endl;

	return 0;
}

#include <queue>

void func2()
{
	int n, k;
	cin >> n >> k;
	int x = 0, l = 0, r = 1,sum = 0;
	priority_queue<int> memoy;
	vector<int> v(n);

	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	for (; r < n; r++)
	{
		if (v[r] > v[l])
		{
			x++;
			memoy.push(v[r] - v[l]);
			l = r + 1;
			r++;
		}
	}
	for (int i = 0; i < k; i++)
	{
		if (!memoy.empty())
		{
			sum += memoy.top();
			memoy.pop();
		}
	}

	cout << sum << endl;
}

//int countPath(vector<vector<int> >& CityMap, int n, int m) {
//
//}


//=======================================================================================
#define ll long long

void func3()
{
	const ll sum = 1e8 + 5;
	ll n, x, Less = 0;
	cin >> n >> x;
	vector<int> v(n);

	for (int i = 0; i < n; i++)
	{
		cin >> v[i];
	}

	sort(v.begin(), v.end());

	if (n - x > 0)
	{
		Less += v[n - x] * x;
		for (int i = n - x + 1; i < n; i++)
		{
			Less += v[i] - v[n - x];
		}
	}
	else
	{
		for (int i = 0; i < n; i++)
		{
			Less += v[i];
		}
	}

	cout << Less << endl;
}


int main()
{
	func3();
	return 0;
}